package com.gitee.qdbp.jdbc.operator.where;

import com.gitee.qdbp.able.jdbc.model.LikeValue;
import com.gitee.qdbp.jdbc.api.SqlBoot;
import com.gitee.qdbp.jdbc.operator.DbBinaryOperator;
import com.gitee.qdbp.jdbc.operator.base.DbAbstractOperator;
import com.gitee.qdbp.jdbc.sql.SqlBuffer;
import com.gitee.qdbp.jdbc.sql.SqlTools;

/**
 * 二元Like运算符
 *
 * @author zhaohuihua
 * @version 20200123
 */
public class DbBinaryNotLikeOperator extends DbAbstractOperator implements DbBinaryOperator {

    /** 版本序列号 **/
    private static final long serialVersionUID = 1L;

    public DbBinaryNotLikeOperator() {
        super("Not Like", "NotLike");
    }

    @Override
    public SqlBuffer buildSql(String columnName, Object columnValue, SqlBoot sqlBoot) {
        if (columnValue instanceof LikeValue) {
            LikeValue likeValue = (LikeValue) columnValue;
            return sqlBoot.newSqlBuilder().ad(columnName).ad("NOT").ad(sqlBoot.sqlDialect().buildLikeSql(likeValue)).out();
        } else {
            String stringValue = columnValue == null ? null : SqlTools.unwrapDbVariable(columnValue).toString();
            return sqlBoot.newSqlBuilder().ad(columnName).ad("NOT").ad(sqlBoot.sqlDialect().buildLikeSql(stringValue)).out();
        }
    }

}
